package homework_06;

import java.util.ArrayList;

public class Student {
    String name;
    int stuNo;
    int score;

    static Student[] studs = new Student[50];
    static {
        for(int m=0;m<studs.length;m++){
            if(studs[m]==null){
                studs[m]= new Student("null",0,0);
            }else{
                continue;
            }
        }
    }

    public Student(){

    }

    public Student(String name,int stuNo,int score){
        this.name = name;
        this.stuNo = stuNo;
        this.score = score;
    }

    public void show(){
        System.out.println(this.name+"/"+this.stuNo+"/"+this.score);
    }

    public static boolean stuAdd(Student stu){
        boolean flg = false;
        for(int i=0;i<studs.length;i++){
            if(studs[i].name == "null"){
                studs[i]=stu;
                flg = true;
                break;
            }else{
                continue;
            }
        }
        return flg;
    }

    public static void stuSort(){
        for(int i=1;i<studs.length;i++){
            for(int j=0;j<studs.length-1;j++){
                if(studs[j].score<studs[j+1].score){
                    Student stud = studs[j];
                    studs[j] = studs[j+1];
                    studs[j+1] = stud;
                }
            }
        }
    }

    public static void showAll(){
        for (int i=0;i<studs.length;i++){
            if(studs[i].name=="null"){
                break;
            }else{
                System.out.println(studs[i].toString());
            }
        }
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", stuNo=" + stuNo +
                ", score=" + score +
                '}';
    }
}
